package com.sj.purchase.modules.stages.config;

import com.sj.purchase.modules.stages.config.task.StagesTask;
import com.sj.purchase.util.Date2StrUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.Date;

/**
 * @author yangrd
 * @date 2018/8/11
 **/
@Configuration
public class StagesScheduler {

    private StagesTask stagesTask;

    private static Logger LOGGER = LoggerFactory.getLogger(StagesScheduler.class);

    @Autowired
    public StagesScheduler(StagesTask stagesTask) {
        this.stagesTask = stagesTask;
    }

    @Scheduled(cron = "0 5 3 * * ?")
    public void stockTask() {
        Date fivesDaysAgo = DateUtils.addDays(new Date(),-5);
        String fivesDaysAgoStr = Date2StrUtils.str(fivesDaysAgo);
        stagesTask.syncStagesOrder(fivesDaysAgoStr);
        stagesTask.syncWMSOutOrder(fivesDaysAgoStr);
        LOGGER.info("{} 订单分期数据同步完成", fivesDaysAgoStr);
    }
}
